package com.pc.admin.config;

import com.pc.admin.exception.NoSuchStrategyException;
import com.pc.admin.util.CommonResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
 * GlobalErrorCatch
 *
 * @author <a href="https://www.lvfeiy.top">lfy</a>
 * @date 2023/6/23 22:32
 */
@ControllerAdvice
public class GlobalErrorCatch {

    @ExceptionHandler(value = NoSuchStrategyException.class)
    public CommonResult<String> catchNoSuchStrategy(NoSuchStrategyException e){
        return CommonResult.sysError(e.getMessage());
    }

    @ExceptionHandler(value=Throwable.class)
    @ResponseBody
    public CommonResult<String> catchGlobalError(Throwable ex){
        return CommonResult.sysError(ex.getMessage());
    }
}
